/// <summary>
/// 计算机建造者类，实现了计算机建造者接口
/// </summary>
public class ComputerBuilder : IComputerBuilder
{
  private Computer _computer = new Computer();

  public IComputerBuilder SetCpu(string cpu)
  {
    _computer.Cpu = cpu;
    return this;
  }

  public IComputerBuilder SetMemory(int gb)
  {
    _computer.Memory = gb;
    return this;
  }

  public IComputerBuilder SetStorage(int gb)
  {
    _computer.Storage = gb;
    return this;
  }

  public IComputerBuilder SetGpu(string gpu)
  {
    _computer.Gpu = gpu;
    return this;
  }

  public IComputerBuilder SetOs(string os)
  {
    _computer.Os = os;
    return this;
  }

  public IComputerBuilder WithBluetooth(bool enable = true)
  {
    _computer.HasBluetooth = enable;
    return this;
  }

  public IComputerBuilder WithWifi(bool enable = true)
  {
    _computer.HasWifi = enable;
    return this;
  }

  public Computer Build()
  {
    // 可以在这里做验证
    if (string.IsNullOrEmpty(_computer.Cpu))
      throw new InvalidOperationException("CPU 是必需的！");

    var built = _computer;
    _computer = new Computer(); // 可选：重置以便下次使用
    return built;
  }
}